﻿﻿using System;
using UnityEngine;
using Object = UnityEngine.Object;

public class CardUtils
{
    public static GameObject GetCardInstance(CardPair cardPair, BaseEntity caller, int belongSlot, CardBelongType cardBelongType = CardBelongType.Basic, DeckType deckBelongType = DeckType.Action)
    {
        switch (cardBelongType)
        {
            case CardBelongType.Basic:
            case CardBelongType.Drag:
            case CardBelongType.Icon:
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }

        cardPair.belongSlot = belongSlot;
        
        GameObject cardInstance = Object.Instantiate(ResourceLoader.cardBelongPrefabMap[cardBelongType]);
        
        // 这边是用来显示的
        cardInstance.GetComponent<CardDisplayerMonobehaviour>().SetPairData(cardPair);

        // 这边是实际的参数
        BasicCard cardInfo = cardInstance.GetComponent<BasicCard>(); 
        cardInfo.belongDeckType = deckBelongType;

        cardInfo.SetPairData(cardPair);
        cardInfo.caller = caller;

        cardInstance.transform.localScale = Vector3.zero;

        return cardInstance;
    }
}
